<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="pers.zdb.ag.pojo.Address" %>
<%@ page import="pers.zdb.ag.AddressUtils" %>
<%
    System.out.println("getRemoteAddr:"+request.getRemoteAddr());
    System.out.println("getRemoteAddr:"+request.getRemoteAddr());

    Map map = new HashMap();


    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    request.setCharacterEncoding("UTF-8");

    String result = "";
    String location = request.getParameter("location");

    if (location==null) location="";

    if (location!=null&&location.trim().length()>0){
        if(location.indexOf(",")==-1){
            result = "经纬度请用英文逗号隔开(如 113.575895,23.116969 )";

            map.put("status",-1);
            map.put("success",false);
            map.put("result",result);

        }else{
            double longitude = Double.parseDouble(location.split(",")[0]);
            double latitude = Double.parseDouble(location.split(",")[1]);
            Address address = AddressUtils.getAddress(longitude,latitude);
            result = address.getProvince()+"-"+address.getCity()+"-"+address.getArea();

            map.put("status",1);
            map.put("success",true);
            map.put("result",result);

        }
    }else {
        result = "请输入经纬度";
        map.put("status",-2);
        map.put("success",false);
        map.put("result",result);
    }



    /**
     * 返回json
     */
    PrintWriter out = response.getWriter();
    out.write(JSON.toJSONString(map));
    out.close();

%>
